<?php
namespace app\admin\controller;
/*
 * @Author: 小悟空56
 * @Date: 2022-02-25 17:15:30
 * @LastEditTime: 2022-03-29 13:20:18
 * @LastEditors: 小悟空56
 * @Description: 描述：
 * @FilePath: \copy.copy.com\app\admin\controller\Loginlog.php
 * 白月光
 */
use app\admin\model\LoginLog as log;
use app\Request;
use think\facade\View;
use think\facade\Db;
use liliuwei\think\Jump;

class LoginLog
{
    use Jump;
    public function index(){

        // $username=$index::distinct(true)->select()->toarray();
        // 去重：distinct
        $username=Db::table('loginlog')->distinct(true)->order('username', 'desc')->field('username')->select();
        // var_dump($username);
         $arr = array();
         foreach ($username as $k=>$v){
             $arr[$k]['username'] = $v['username'];
         }
        //  var_dump($arr);
        View::assign('arr',$arr);
        return View::fetch();
    
    }

    // 登录日志显示
    public function loginLogList(Request $request){

        // $log=new log();
        // $data=$log::order('id','desc')->select()->toArray();
        // return lay_msg(0,'success',count($data),$data);

        $log = new log();
        $input = $request->param();
        // var_dump($input);exit;
        $username = array();
        if ($request->param('username') != "") {
             // 条件查询
             $username[] = $input['username'];
             $data = $log->withSearch(['username','create_time'],[
                 'username' =>$username,
                 'create_time' =>$request->param('time')
             ])->order('id', 'desc')->select()->toArray();
            //  return lay_msg(0,'success',count($data),$data);
        }else{
            // $data = $log->order('id', 'desc')->page($request->param('page'),$request->param('limit'))->select()->toArray();
            $data=$log::order('id','desc')->select()->toArray();
        }
        
        $data = mb_convert_encoding( $data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
        return lay_msg(0,'success',count($data),$data);
    }

    // 删除日志单条日志
    public function delLoginLog(Request $request){
      
        $log = new log();
        $log->destroy($request->param('id'));
        return $this->success('删除成功');
    }

}
